﻿/*
 * 文件名称：
 * 程序员：huangsb
 * 创建时间：2008/05/20
 * 
 * 功能说明：角色添加、修改
 * 
 * 修改人员：
 * 
 * 修改日期：
 * 
 * 修改记录：
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common.WebHelper;

public partial class Whir_System_Module_Role_AddRole : System.Web.UI.Page
{
    protected string id = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        RoleHelper.IsLogin();    //登录判断

        if (RoleHelper.AdminCache.typeID != 1)
        {
            JsHelper.redirect(Page, "当前用户不是管理员，无法继续操作！", "../../Main.aspx");
        }

        if (Request.QueryString["id"] != null)
            this.id = Whir.Common.WebHelper.NetRequest.SafeRequest(Page, "id");

        if (!IsPostBack)
        {
            if (this.id != "")
                setData();
        }
    }

    protected void setData()
    {
        Whir.Model.Whir_AdminRole model = new Whir.SQLServerDAL.Whir_AdminRole().GetModel(int.Parse(this.id));

        this.txtRoleName.Text = model.roleName;
        this.txtRoleDesc.Text = model.roleDesc;
    }

    protected Whir.Model.Whir_AdminRole getModel()
    {
        Whir.Model.Whir_AdminRole model;

        if (this.id != "")
            model = new Whir.SQLServerDAL.Whir_AdminRole().GetModel(int.Parse(this.id));
        else
            model = new Whir.Model.Whir_AdminRole();

        return model;
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Whir.Model.Whir_AdminRole model = this.getModel();
        Whir.SQLServerDAL.Whir_AdminRole bll = new Whir.SQLServerDAL.Whir_AdminRole();

        if (this.id != "")
        {
            model.roleName = this.txtRoleName.Text.Replace("|", " ");
            model.roleDesc = this.txtRoleDesc.Text;

            model.updateDate = DateTime.Now;
            model.updateUserID = RoleHelper.GetAdminID();

            bll.Update(model);
            OLAdd("修改角色信息", 2);
        }
        else
        {
            model.roleName = this.txtRoleName.Text.Replace("|", " ");
            model.roleDesc = this.txtRoleDesc.Text;
            model.roleValue = RoleHelper.getRoleDefault();
            model.columnIDs = "";

            model.createDate = DateTime.Now;
            model.createUserID = RoleHelper.GetAdminID();
            model.updateDate = DateTime.Now;
            model.updateUserID = RoleHelper.GetAdminID();

            bll.Add(model);
            OLAdd("添加角色信息", 1);
        }
    }

    //操作日志
    protected void OLAdd(string title, int type)
    {
        Whir.Log.Model.Whir_OperateLog model = new Whir.Log.Model.Whir_OperateLog();
        model.title = title;
        model.operateType = type;
        model.operateResult = true;
        model.operateDesc = "";

        Whir.Log.OperateLog.Add(model);
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("RoleList.aspx");
    }
}
